package org.tacademy.mysurface;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MySurFaceView extends SurfaceView implements SurfaceHolder.Callback {
	
	SurfaceHolder holder;
	
	public MySurFaceView(Context context) {
		super(context);
		init(context);
	}
	
	public MySurFaceView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
	public void init(Context context){
		holder = getHolder();
		holder.addCallback(this);
	}

	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		
	}

	public void surfaceCreated(SurfaceHolder holder) {
		draw();
	}

	public void surfaceDestroyed(SurfaceHolder holder) {
		
	}
	
	public void draw(){
		Canvas canvas = null;
		
		try{
			canvas = holder.lockCanvas(null);
			Paint paint = new Paint();
			paint.setColor(Color.WHITE);
			canvas.drawLine(100.0f, 100.0f, 200.0f, 200.0f, paint);
		}catch(Exception e){
			
		}finally{
			if(canvas != null){
				holder.unlockCanvasAndPost(canvas);
			}
		}
	}

}
